package cn.javastudy.jdbc;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 全局配置类，加载数据库连接信息
 */
public class GlobalProperties {

    /**
     * 数据库连接驱动
     */
    public static String driverName;

    /**
     * 数据库地址
     */
    public static String url;

    /**
     * 用户名
     */
    public static String user;

    /**
     * 密码
     */
    public static String password;

    static {
        InputStream inputStream = GlobalProperties.class.getClassLoader().getResourceAsStream("db.properties");
        Properties prop = new Properties();
        try {
            prop.load(inputStream);
        } catch (IOException e) {
            System.out.println("读取db.properties配置文件失败");
            throw new RuntimeException(e);
        }
        driverName = prop.getProperty("driverName");
        url = prop.getProperty("url");
        user = prop.getProperty("username");
        password = prop.getProperty("password");
    }

}
